package cn.clq.ymcc.web.controller;

import cn.clq.ymcc.domain.Login;
import cn.clq.ymcc.dto.CourseOnSendMessageDto;
import cn.clq.ymcc.service.IMessageSmsService;
import cn.clq.ymcc.domain.MessageSms;
import cn.clq.ymcc.query.MessageSmsQuery;
import cn.clq.ymcc.result.JSONResult;
import cn.clq.ymcc.result.PageList;
import cn.clq.ymcc.util.VerifyCodeUtils;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/messageSms")
public class MessageSmsController {

    @Autowired
    public IMessageSmsService messageSmsService;

//    /**
//     * @description: 课程发布成功之后，给相关用户发送短信
//     * @param: dto
//     * @return: cn.clq.ymcc.result.JSONResult
//     * @author clqlongbao
//     * @date: 2022/7/25 20:19
//     */
//    @PostMapping("/sendMessage")
//    public JSONResult sendSms(@RequestBody CourseOnSendMessageDto courseOnSendMessageDto){
//        messageSmsService.sendMessage(courseOnSendMessageDto);
//        return JSONResult.success();
//    }

    /**
    * 保存和修改公用的，加入和移出黑名单
    */
    @PostMapping("/save")
    public JSONResult saveOrUpdate(@RequestBody MessageSms messageSms){
        if(messageSms.getId()!=null){
            messageSmsService.updateById(messageSms);
        }else{
            messageSmsService.insert(messageSms);
        }
        return JSONResult.success();
    }

    /**
    * 删除对象
    */
    @DeleteMapping("/{id}")
    public JSONResult delete(@PathVariable("id") Long id){
        messageSmsService.deleteById(id);
        return JSONResult.success();
    }

    /**
   * 获取对象
   */
    @GetMapping(value = "/{id}")
    public JSONResult get(@PathVariable("id")Long id){
        return JSONResult.success(messageSmsService.selectById(id));
    }


    /**
    * 查询所有对象
    */
    @GetMapping("/list")
    public JSONResult list(){
        return JSONResult.success(messageSmsService.selectList(null));
    }


    /**
    * 带条件分页查询数据
    */
    @PostMapping("/pagelist")
    public JSONResult page(@RequestBody MessageSmsQuery query){
        Page<MessageSms> page = new Page<MessageSms>(query.getPage(),query.getRows());
        page = messageSmsService.selectPage(page);
        return JSONResult.success(new PageList<MessageSms>(page.getTotal(),page.getRecords()));
    }
}
